import time
import ddt
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from Base.BaseSetings import TestData_dir
# from WoniuBossPOM.Student_Management_POM_PZY import Stu_Sys_Mamagement
from WoniuBossPOM.All_Management_POM import All_Mamagement



class woniuboss():
    def __init__(self):
        self.dr = All_Mamagement()

    # def login(self):
    #     self.dr.get_home_user_name_obj().send_keys('WNCD000')
    #     self.dr.get_home_password_obj().send_keys('woniu123')
    #     self.dr.get_home_login_obj().click()

    def test_stu(self,stuName):   #学员信息
        time.sleep(5)
        self.dr.get_home_student_obj().click()
        self.dr.get_home_stu_info_obj().click()
        #下拉框
        time.sleep(2)
        ele_select1 = self.dr.get_home_area_obj()   #【区域】下拉框
        Select(ele_select1).select_by_index(1)
        time.sleep(2)
        ele_select2 = self.dr.get_home_dire_obj()  #[方向]下拉框
        Select(ele_select2).select_by_index(3)
        time.sleep(2)
        ele_select3 = self.dr.get_home_class_obj()  # [班级]下拉框
        Select(ele_select3).select_by_index(2)
        time.sleep(2)
        ele_select4 = self.dr.get_home_status_obj() # [状态]下拉框
        Select(ele_select4).select_by_index(4)
        time.sleep(2)
        self.dr.get_home_stu_name_obj().send_keys(stuName)  #输入学员姓名
        time.sleep(2)
        self.dr.get_home_search_obj().click()  #点击【搜索】按钮
        result = self.dr.get_stu().text
        return result


    def alter(self):  #修改操作
        self.dr.get_home_decode_obj().click()  #解密
        self.dr.get_home_decode1_obj().send_keys('woniu123')
        self.dr.get_home_access_obj().click()
        time.sleep(2)
        self.dr.get_home_alter_obj().click()  #[修改]按钮
        time.sleep(2)
        ele_select5 = self.dr.get_home_edu_obj()  # [学历]下拉框
        Select(ele_select5).select_by_index(1)
        time.sleep(2)
        self.dr.get_home_save_obj().click()  #[保存]按钮
        time.sleep(2)
        self.dr.get_home_access1_obj().click()   #[确认]按钮

    def search_user(self):   #用户管理  用户查询
        self.dr.get_home_system_obj().click()
        self.dr.get_home_system_user_obj().click()
        self.dr.get_home_staff_name_obj().send_keys('刘菲菲')
        self.dr.get_home_user_name_obj().send_keys('WNCD002')
        self.dr.get_home_search1_obj().click()
        result1 = self.dr.get_user().text
        return result1

    def roleadd(self):    #给用户增加角色
        self.search_user()
        self.dr.get_home_role_obj().click()
        self.dr.get_home_addrole_obj().click()
        self.dr.get_home_access2_obj().click()
        time.sleep(2)
        self.dr.get_home_access3_obj().click()
        time.sleep(2)
        info = self.dr.get_home_closedoc_obj().click()
        return info

    def alterrole(self):   #修改用户描述
        self.dr.get_home_system_obj().click()
        self.dr.get_home_system_user_obj().click()
        self.dr.get_home_user_name_obj().send_keys('WNCD002')
        time.sleep(2)
        self.dr.get_home_alterrole_obj().click()
        self.dr.get_home_alterrole1_obj().clear()
        self.dr.get_home_alterrole1_obj().send_keys('我是班主任')
        self.dr.get_home_saveuser_obj().click()
        self.dr.get_home_access5_obj().click()
        result2 = self.dr.get_teacherdata().text
        return result2

    def alterpwd(self):  #重置密码
        self.search_user()
        self.dr.get_home_alterpwd_obj().click()
        self.dr.get_home_pwd_obj().clear()
        self.dr.get_home_pwd_obj().send_keys('woniu123')
        time.sleep(2)
        self.dr.get_home_savepwd_obj().click()
        time.sleep(2)
        self.dr.get_home_access4_obj().click()
        time.sleep(2)
        self.dr.get_home_closedoc_obj().click()

    def role_management(self,username):  #角色管理   新增角色
        time.sleep(2)
        self.dr.get_home_system_obj().click()
        self.dr.get_home_role1_obj().click()
        self.dr.get_home_roleadd_obj().click()
        self.dr.get_home_role_name_obj().click()
        self.dr.get_home_role_name_obj().send_keys(username)
        self.dr.get_home_save_role_obj().click()
        self.dr.get_home_access6_obj().click()

    def search_role(self,username):   # 查询新增角色
        self.role_management(username)
        time.sleep(2)
        self.dr.get_home_rolesearch_obj().send_keys(username)
        self.dr.get_home_rolesearch_obj().click()     #查询按钮

    def alter_role(self,username):     #修改角色
        self.search_role(username)
        time.sleep(2)
        self.dr.get_home_alter_role_obj().click()
        self.dr.get_home_role_name_obj().clear()   #清空角色框
        self.dr.get_home_role_alter_obj().click()  #点击保存按钮
        self.dr.get_home_access6_obj().click()    #确认键跟新增后的确认键为同一个


    def closeBrower(self):    #关闭网页
        self.dr.get_home_close_obj()




if __name__ == '__main__':
    run = WoniuBoss()
    # run.login()
    # run.stu('陈雪')
    # run.alter()
    # run.search_user()
    # run.roleadd()
    # run.alterrole()
    # run.alterpwd()
    # run.role_management('老板')
    # run.search_role('老板')
    # run.alter_role('老板')
    # run.closeBrower()
